package com.busdepot.webbapp.domain;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.busdepot.webapp.domain.AbstractPart;
import com.busdepot.webapp.domain.PartService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "/spring-service.xml" })
public class PartServiceTestIntegration {
	
	@Autowired
	private ApplicationContext applicationContext;
	
	@Autowired
	PartService partService;
	
	/*
	@Test
	public void saveNewPart(){
		Long time = System.currentTimeMillis();
		String name = "test part" + time;
		AbstractPart abstractPart = new AbstractPart();
		abstractPart.setPartNumber("12345678TRT");
		abstractPart.setName(name);
		abstractPart.setDescription("This is the test part description");
		abstractPart.setPrice(175);
		abstractPart.setCore(75);
		abstractPart.setCost(50);
		abstractPart.setHotItem(true);
		abstractPart.setSpecial(false);
		abstractPart.setImage("test");  // 4 char max
		abstractPart.setVendorId(520947);  
		abstractPart.setAvailability("4-7 working days");
		abstractPart.setDbBusDepot("369087TD");
		abstractPart.setDbImc("98456TY");
		abstractPart.setListPrice(456.76);
		abstractPart.setXref("345dfg");
		abstractPart.setWeight(3.45);  // 6 char max - 4,2
		abstractPart.setUnitMeasure("4.35 units");
		abstractPart.setBrand("part brand");
		abstractPart.setNote("test part note");
		abstractPart.setFootnote("set test footnote");
		abstractPart.setMoreInfo("test part more info");
		
		partService.save(abstractPart);
	}
	
	@Test
	public void updatePart(){
		int id = 283400;
		List <AbstractPart> partList = partService.getPartById(id);
		AbstractPart abstractPart = partList.get(0);
		abstractPart.setNote("updated note");
		partService.save(abstractPart);
	}
	*/
	@Test
	public void getPartById(){
		int id = 500;
		List <AbstractPart> partList = partService.getPartById(id);
		Assert.assertTrue("part list is empty", !partList.isEmpty());	
	}
	
	@Test
	public void getPartByPartNumber(){
		String partNumber = "071251497B";
		List <AbstractPart> partList = partService.getPartByNumber(partNumber);
		Assert.assertTrue("part list is empty", !partList.isEmpty());	
	}
	
}
